//
//  FYGuideView.m
//  MockProject
//
//  Created by FanYu on 22/8/2016.
//  Copyright © 2016 niuzhaowang. All rights reserved.
//

#import "YXGuideView.h"
#import "Config.h"

@interface YXGuideView ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UIButton *startButton;

@end


@implementation YXGuideView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // self
        self.backgroundColor = [UIColor whiteColor];
        
        // image view
        self.imageView = [[UIImageView alloc] init];
        self.imageView.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.imageView];
        
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            // iphone 4
            if ([SDVersion deviceSize] == Screen3Dot5inch) {
                make.left.equalTo(self.mas_left).offset(20);
                make.right.equalTo(self.mas_right).offset(-28);
                make.top.equalTo(self.mas_top).offset(10);
                make.height.mas_equalTo(SCREEN_WIDTH - 56);
            } else {
                make.left.equalTo(self.mas_left).offset(18 * kScaleFactor);
                make.right.equalTo(self.mas_right).offset(-18 * kScaleFactor);
                make.top.equalTo(self.mas_top).offset(61 * kScaleFactor);
                make.height.mas_equalTo(SCREEN_WIDTH - 36 *kScaleFactor);
            }
        }];
        
        // title label
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor colorWithHexString:@"8b8b8b"];
        [self addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.imageView.mas_bottom).offset(32 * kScaleFactor);
            make.centerX.equalTo(self);
        }];
        
        // detail label
        self.detailLabel = [[UILabel alloc] init];
        self.detailLabel.textColor = [UIColor colorWithHexString:@"8b8b8b"];
        self.detailLabel.font = [UIFont systemFontOfSize:20];
        [self addSubview:self.detailLabel];
        [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15 * kScaleFactor);
            make.centerX.equalTo(self);
        }];
        
        // start button
        self.startButton = [[UIButton alloc] init];
        self.startButton.layer.borderWidth = 1;
        self.startButton.layer.cornerRadius = 17;
        self.startButton.layer.borderColor = [UIColor colorWithHexString:@"ff7000"].CGColor;
        self.startButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.startButton setTitle:@"进入泡泡" forState:UIControlStateNormal];
        [self.startButton setTitleColor:[UIColor colorWithHexString:@"ff7000"] forState:UIControlStateNormal];
        [self addSubview:self.startButton];
        [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.detailLabel.mas_bottom).offset(15 * kScaleFactor);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(140, 34));
        }];
        
        [self.startButton addTarget:self action:@selector(startButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;

}


- (void)setupWithGuideModel:(YXIntroModel *)introModel {
    self.titleLabel.attributedText = introModel.titleString;
    
    self.detailLabel.text = introModel.detailString;
    
    self.startButton.hidden = introModel.isHiddenbutton;
    
    self.imageView.image = [UIImage imageNamed:introModel.imageString];
}


- (void)startButtonTapped:(UIButton *)sender {
    [self.delegate startButtonTapped];
}

@end
